package cs342.uwosh.edu.MyWorldApp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Switch;
import cs342.uwosh.edu.R;
import cs342.uwosh.edu.MyWorldApp.storage.User;

public class OptionsActivity extends Activity {

	public final static int UPDATE_USER_SETTINGS = 1;
	public final static int UPDATED_USER_SETTINGS = 0;
	
	User currentUser;
	Switch stealthOption, placesOption, satMode;
	
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.options);
	    Intent myIntent = getIntent();
	    currentUser = myIntent.getParcelableExtra("user");
	    placesOption = ( Switch ) findViewById(R.id.stealthSwitch);
	    stealthOption = ( Switch ) findViewById(R.id.stealthSwitch);
	    
	    placesOption.setChecked(currentUser.isSearchingPlaces());
	    stealthOption.setChecked(currentUser.isStealthed());
	    
	    
	}
	
	public void save(View view) {
		currentUser.setStealthed(stealthOption.isChecked());
		currentUser.setSearchingPlaces(placesOption.isChecked());
		
		updateOptionsOnCloud(currentUser);

		onBackPressed();
		
	}
	public void cancel(View view) {
		onBackPressed();
	}
	public void onBackPressed() {
    	Intent myIntent = new Intent(this,
				MyWorldAppActivity.class);
		myIntent.putExtra("user", currentUser);
		
		setResult(UPDATED_USER_SETTINGS, myIntent);
    	super.onBackPressed();
    }
	
	public void updateOptionsOnCloud(User user) {
		//TODO send data to cloud
	}
}
